package edu.gdkm.sql.dao;

import edu.gdkm.sql.pojo.Order;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface OrderMapper {

    // Create
    @Insert("INSERT INTO `order` (userinfoid, orderdate) VALUES (#{userinfoid}, #{orderdate})")
    int insertOrder(Order order);

    // Update
    @Update("UPDATE `order` SET userinfoid = #{userinfoid}, orderdate = #{orderdate} WHERE id = #{id}")
    int updateOrder(Order order);

    // Read
    @Select("SELECT * FROM `order` WHERE id = #{id}")
    Order getOrderById(int id);

    @Select("SELECT * FROM `order`")
    List<Order> getAllOrders();
    // 新添加的方法：根据userinfoid查询order
    @Select("SELECT * FROM `order` WHERE userinfoid = #{userinfoid}")
    List<Order> getOrdersByUserId(int userinfoid);
    // Delete
    @Delete("DELETE FROM `order` WHERE id = #{id}")
    int deleteOrder(int id);
}